import { getControl, getOptions } from '../../../Zform/controls';
import { getMehtodWithUrlControl, getSwitchOpt } from './common';
//地图的默认密钥
const initSereKey = {
    amap: 'c8fc4840588729945711e0db80ec369a', //高德地图key
    amapPrivateKey: 'c0a105a1ae4bcc9a6821497f987b9cb7', //高德地图秘钥
    qqmap: '7F7BZ-R7ZWZ-GXHX5-ZSQQV-ADFTF-AMFJ2', //腾讯地图key
};

export default {
    label: '地图选点',
    value: 13,
    getFieldPropertiesFormItems({ formItemsRef: itemsRef, componentList: controlList, formItemsLinkAction }) {
        return [
            {
                key: 'mapType',
                label: '地图类型',
                show: false,
                labelFocused: true,
                render(form, changeFormItems) {
                    return getControl('Radio.Group', {
                        selectList: [
                            {
                                label: '腾讯',
                                value: 'qqmap',
                            },
                            { label: '高德', value: 'amap' },
                        ],
                        onChange(e) {
                            const val = e.target.value;
                            form.setFieldsValue({
                                secretKey: initSereKey[val],
                            });
                            formItemsLinkAction({
                                changeFormItems,
                                formItems: itemsRef.current,
                                values: { secretKey: initSereKey[val] },
                                form,
                                controlList,
                                excludeKeys: [],
                            });
                        },
                    });
                },
                options: getOptions({ required: true, initialValue: 'qqmap' }),
            },

            {
                key: 'secretKey',
                label: '地图key',
                show: false,
                labelFocused: true,
                render(form, changeFormItems) {
                    return getControl('Input');
                },
                options: getOptions({ required: true, initialValue: initSereKey['qqmap'] }),
            },
            {
                key: 'privateKey',
                label: '地图密钥',
                show: false,
                labelFocused: true,
                render(form, changeFormItems) {
                    return getControl('Input');
                },
                options: getOptions({ required: true, initialValue: initSereKey['amapPrivateKey'] }),
            },
            {
                key: 'disabledMapWeb',
                show: false,
                label: '禁止调用地图web服务',
                labelFocused: true,
                ...getSwitchOpt({ initialValue: false }, (form, changeFormItems) => ({
                    onChange(checked) {
                        formItemsLinkAction({
                            changeFormItems,
                            formItems: itemsRef.current,
                            values: { disabledMapWeb: Number(checked) },
                            form,
                            controlList,
                            excludeKeys: [],
                        });
                    },
                })),
            },
            getMehtodWithUrlControl({
                key: 'webserviceUrlDO',
                label: '调用地图web服务的代理地址',
                methodKey: 'urlMethod',
                urlKey: 'url',
                initialValue: {
                    urlMethod: 'post',
                    url: '/form-service/webapi/geography/webService',
                },
            }),
        ];
    },
};
